package ldh.im.fxbase.data.pojo.status;

import ldh.im.dto.enums.MessageType;
import ldh.im.fxbase.data.pojo.ImMessage;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

public class ImCollectContent {

    private String content;
    private String fileContent;
    private String fromUserId;
    private String toUserId;
    private String groupCode;
    private Date messageTime;
    private MessageType messageType;
    private String messageId;

    private List<ImCollectContent> refCollectContents;  // 关联消息内容

    public ImCollectContent(ImMessage message) {
        fromUserId = message.getFromUserId();
        toUserId = message.getToUserId();
        groupCode = message.getGroupCode();
        messageType = message.getMessageType();
        messageId = message.getServerId();
        messageTime = message.getCreateDateTime();
        content = message.getContent();
        fileContent = message.getExt();

        if (message.getRefMessageIds() != null) {
            refCollectContents = message.getRefMessages().stream().map(ImCollectContent::new).collect(Collectors.toList());
        }
    }

    public ImMessage toMessage() {
        ImMessage message = new ImMessage();
        message.setServerId(messageId);
        message.setFromUserId(fromUserId);
        message.setToUserId(toUserId);
        message.setGroupCode(groupCode);
        message.setContent(content);
        message.setExt(fileContent);
        message.setMessageType(messageType);
        message.setFileStatus(ImMessageFileStatus.downloaded);
        return message;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getFromUserId() {
        return fromUserId;
    }

    public void setFromUserId(String fromUserId) {
        this.fromUserId = fromUserId;
    }

    public String getToUserId() {
        return toUserId;
    }

    public void setToUserId(String toUserId) {
        this.toUserId = toUserId;
    }

    public String getGroupCode() {
        return groupCode;
    }

    public void setGroupCode(String groupCode) {
        this.groupCode = groupCode;
    }

    public Date getMessageTime() {
        return messageTime;
    }

    public void setMessageTime(Date messageTime) {
        this.messageTime = messageTime;
    }

    public MessageType getMessageType() {
        return messageType;
    }

    public void setMessageType(MessageType messageType) {
        this.messageType = messageType;
    }

    public List<ImCollectContent> getRefCollectContents() {
        return refCollectContents;
    }

    public void setRefCollectContents(List<ImCollectContent> refCollectContents) {
        this.refCollectContents = refCollectContents;
    }

    public String getMessageId() {
        return messageId;
    }

    public void setMessageId(String messageId) {
        this.messageId = messageId;
    }

    public String getFileContent() {
        return fileContent;
    }

    public void setFileContent(String fileContent) {
        this.fileContent = fileContent;
    }
}
